package com.jeework.common.entity;

import com.jeework.common.config.Global;
import com.jeework.common.utils.StringUtils;
import lombok.Data;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Data
public class Page<T> {
    private List<T> list;
    private boolean isFirst;
    private int pageNo;
    private int prev;
    private long count;
    private int next;
    private int last;
    private boolean isLast;
    private int first;
    private String orderBy;
    private int pageSize;


    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }



    public boolean isFirst() {
        return isFirst;
    }

    public void setFirst(boolean first) {
        isFirst = first;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getPrev() {
        return prev;
    }

    public void setPrev(int prev) {
        this.prev = prev;
    }

    public long getCount() {
        return count;
    }

    public void setCount(long count) {
        this.count = count;
    }

    public int getNext() {
        return next;
    }

    public void setNext(int next) {
        this.next = next;
    }


    public int getLast() {
        return last;
    }

    public void setLast(int last) {
        this.last = last;
    }

    public boolean isLast() {
        return isLast;
    }

    public void setLast(boolean last) {
        isLast = last;
    }

    public int getFirst() {
        return first;
    }

    public void setFirst(int first) {
        this.first = first;
    }

    public String getOrderBy() {
        return orderBy;
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public Page() {

    }

    public Page(HttpServletRequest request) {
        String page_no = request.getParameter("pageNo");
        String page_size = request.getParameter("pageSize");
        Integer pageNo =0;
        Integer pageSize =0;
        if (StringUtils.isEmpty(page_no) && StringUtils.isEmpty(page_size)) {
            pageNo = 1;
            pageSize = Global.getPageSize();

        }else{
            pageNo = Integer.parseInt(page_no);
            pageSize = Integer.parseInt(page_size);
        }
        this.setPageNo(pageNo);
        this.setPageSize(pageSize);
    }
}
